using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace InduMall.Core.Models.Mapping
{
    public class CartItemMap : EntityTypeConfiguration<CartItem>
    {
        public CartItemMap()
        {
            // Primary Key
            this.HasKey(t => t.CartItemId);

            // Properties
            this.Property(t => t.CartItemId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.ProductName)
                .IsRequired()
                .HasMaxLength(32);

            this.Property(t => t.Sku)
                .IsRequired()
                .HasMaxLength(60);

            // Table & Column Mappings
            this.ToTable("CartItem");
            this.Property(t => t.CartItemId).HasColumnName("CartItemId");
            this.Property(t => t.ShoppingCartId).HasColumnName("ShoppingCartId");
            this.Property(t => t.ProductId).HasColumnName("ProductId");
            this.Property(t => t.ProductName).HasColumnName("ProductName");
            this.Property(t => t.ProductPrice).HasColumnName("ProductPrice");
            this.Property(t => t.Quantity).HasColumnName("Quantity");
            this.Property(t => t.Sku).HasColumnName("Sku");
            this.Property(t => t.Discount).HasColumnName("Discount");

            // Relationships
            this.HasRequired(t => t.Product)
                .WithMany(t => t.CartItems)
                .HasForeignKey(d => d.ProductId);
            this.HasRequired(t => t.ShoppingCart)
                .WithMany(t => t.CartItems)
                .HasForeignKey(d => d.ShoppingCartId);

        }
    }
}
